package com.hhkj.admin.order.common.cont;

import cn.hutool.core.util.ArrayUtil;
import com.hhkj.admin.order.domain.OrderItem;
import com.ruoyi.common.exception.GlobalException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class OrderConst {

    public static final String ORDER_IMPORT_TEMPLATE_NAME = "订单导入模板";

    public static final String EXPORT_EXCEL_TITLE = "订单数据汇总";

    public static final List<OrderItem> ORDER_IMPORT_TEMPLATE_LIST = new ArrayList<>();
    static {
        OrderItem orderItem = OrderItem.builder()
                .name("王大志")
                .idCard("330326199211027412")
                .phone("15721224555")
                .courseName("标准员）")
                .dayAmount(7)
                .price(new BigDecimal("99.99"))
                .build();
        ORDER_IMPORT_TEMPLATE_LIST.add(orderItem);
    }

    @Getter
    public enum StatusEnum {

        NON("无状态", "non", Arrays.asList()),

        PAYING("待支付", "paying", Arrays.asList("paying")),

        PAY_AUDITING("审核中", "payAuditing", Arrays.asList("payAuditing")),

        PAID("已付款", "paid", Arrays.asList("payAuditing", "paid")),

        ONLY_PAID("只查询已付款", "onlyPaid", Arrays.asList("paid")),

        CANCEL("已取消", "cancel", Arrays.asList("cancel")),

        ERROR("支付异常", "error", Arrays.asList("error"));

        private final String name;

        private final String code;

        private List<String> statusCodeList;

        StatusEnum(String name, String code, List<String> statusCodeList) {
            this.name = name;
            this.code = code;
            this.statusCodeList = statusCodeList;
        }

        public static StatusEnum getByCode(String code) {
            for (StatusEnum value : StatusEnum.values()) {
                if (value.code.equals(code)) {
                    return value;
                }
            }
            return NON;
//            throw new GlobalException("找不到对应的code，请联系管理员");
        }
    }

    @AllArgsConstructor
    @Getter
    public enum SourceTypeCode {

        APP("小程序创建", "app"),

        SYSTEM("系统导入", "system");

        private final String name;

        private final String code;

        public static String getNameByCode(String code) {
            for (SourceTypeCode value : SourceTypeCode.values()) {
                if (value.code.equals(code)) {
                    return value.name;
                }
            }
            throw new GlobalException("找不到对应的code，请联系管理员");
        }
    }

    @AllArgsConstructor
    @Getter
    public enum PayMethodEnum {

        ALIPAY("支付宝", "alipay"),

        WECHAT("微信", "wechat"),

        OFFLINE("线下", "offline");

        private final String name;

        private final String code;

        public static String getNameByCode(String code) {
            for (PayMethodEnum value : PayMethodEnum.values()) {
                if (value.code.equals(code)) {
                    return value.name;
                }
            }
            throw new GlobalException("找不到对应的code，请联系管理员");
        }
    }

    @AllArgsConstructor
    @Getter
    public enum ValidateType {

        BEFORE_CREATE("创建订单前", "beforeCreate"),

        BEFORE_PAY("支付订单前", "beforePay");

        private final String name;

        private final String code;
    }
}
